package com.sihuatech.coreagent.controller;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URLDecoder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sihuatech.coreagent.core.communication.entity.RequestSetting;
import com.sihuatech.coreagent.core.communication.entity.StmView;
import com.sihuatech.coreagent.mapper.StmViewMapper;
import com.sihuatech.coreagent.redis.RedisManager;
import com.sihuatech.coreagent.service.SendService;
import com.sihuatech.coreagent.until.Constants;
import com.sihuatech.coreagent.until.XmlParser;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

/**
 * vas侧
 *
 * @author 86186
 *
 */
@Api
@Controller
public class VasController {
	private static final Logger logger = LoggerFactory.getLogger(VasController.class);

//	@Value("${cmcc.vas.sdkUrl}")
//	private String sdkUrl;
//	@Value("${cmcc.vas.chargingCenter.OnDemandBillingQueryUrl}")
//	private String onDemandBillingQueryUrl;
//	@Value("${cmcc.vas.chargingCenter.MonthlyBillingInquiryUrl}")
//	private String monthlyBillingInquiryUrl;
//	@Value("${cmcc.vas.chargingCenter.oderSyncUrl}")
//	private String chargingCenterUrl;
//
//	@Value("${cmcc.vas.partnerUrl}")
//	private String partnerUrl;
//	@Value("${cmcc.vas.boms.url}")
//	private String bomsUrl;
//	@Value("${cmcc.vas.ec.xietong.url}")
//	private String xtmsUrl;

	@Autowired
	private HttpServletRequest req;
	@Autowired
	private SendService sendService;
	@Autowired
	private RedisManager redisManager;

	/*
	 * @Autowired private CoreAgentHttpClient coreAgentHttpClient;
	 */

	@Autowired
	private StmViewMapper stmViewMapper;



	@ApiOperation("vas请求agent转发TSG")
	@ApiImplicitParam(name = "xml", value = "接收的请求报文")
	@PostMapping("/platformSyncPayInfoReq")
	@ResponseBody
	public String platformSyncPayInfoReq() {

		String request = XmlParser.getXml(req);
		String tsgPlatFormResp = "";
		if (StringUtils.isBlank(request))
			logger.error("请求报文为空");
		else
			logger.info("请求报文为：\n" + request);

		try {
			SAXReader saxReader = new SAXReader();
			Document document = saxReader.read(new ByteArrayInputStream(request.getBytes()));
			Element root = document.getRootElement();
			String command = root.getName();
			logger.info("command:" + command);
			String proviceName = StringUtils.substringBetween(request, "<PROV_CODE>", "</PROV_CODE>");
			if(StringUtils.isBlank(proviceName)) {
				String orderId = StringUtils.substringBetween(request, "<OrderId>", "</OrderId>");
				if(StringUtils.isBlank(orderId)) {
					orderId = StringUtils.substringBetween(request, "<ORDER_ID>", "</ORDER_ID>");
				}
				proviceName = orderId.substring(3, 5);
			}

			logger.info("proviceName:" + proviceName);
			RequestSetting info = redisManager.getInfo(command, Constants.TSG_PLATFORM_CODE, proviceName);

			if (info != null) {
				String platformUrl = info.getPlatformUrl();
				logger.info("agent请求地址：" + platformUrl);
				tsgPlatFormResp = sendService.sendToThird(request, platformUrl,"");
				logger.info("返回的报文为:" + tsgPlatFormResp);
			} else {
				logger.info("根据command:" + command + ",TSG平台代码:" + Constants.TSG_PLATFORM_CODE + ",未找到RequestSetting");
				return "根据command:" + command + ",TSG平台代码:" + Constants.TSG_PLATFORM_CODE + ",未找到RequestSetting";
			}

		} catch (DocumentException e) {
			logger.error("获取报文根节点失败", e);
			return "获取报文根节点失败";
		}
		return tsgPlatFormResp;
	}

	@ApiOperation("vas退订请求agent转发TSG")
	@ApiImplicitParam(name = "xml", value = "接收的请求报文")
	@PostMapping("/platFormBillOrCancelReq")
	@ResponseBody
	public String platFormBillOrCancelReq() {

		String request = XmlParser.getXml(req);
		String tsgPlatFormResp = "";
		if (StringUtils.isBlank(request))
			logger.error("请求报文为空");
		else
			logger.info("请求报文为：\n" + request);

		try {
			SAXReader saxReader = new SAXReader();
			Document document = saxReader.read(new ByteArrayInputStream(request.getBytes()));
			Element root = document.getRootElement();
			String command = root.getName();
			logger.info("command:" + command);
			String proviceName = StringUtils.substringBetween(request, "<PROV_CODE>", "</PROV_CODE>");
			if(StringUtils.isBlank(proviceName)) {
				String orderId = StringUtils.substringBetween(request, "<OrderId>", "</OrderId>");
				if(StringUtils.isBlank(orderId)) {
					orderId = StringUtils.substringBetween(request, "<ORDER_ID>", "</ORDER_ID>");
				}
				proviceName = orderId.substring(3, 5);
			}

			logger.info("proviceName:" + proviceName);
			RequestSetting info = redisManager.getInfo(command, Constants.TSG_PLATFORM_CODE, proviceName);

			if (info != null) {
				String platformUrl = info.getPlatformUrl();
				logger.info("agent请求地址：" + platformUrl);
				tsgPlatFormResp = sendService.sendToThird(request, platformUrl,"");
				logger.info("返回的报文为:" + tsgPlatFormResp);
			} else {
				logger.info("根据command:" + command + ",TSG平台代码:" + Constants.TSG_PLATFORM_CODE + ",未找到RequestSetting");
				return "根据command:" + command + ",TSG平台代码:" + Constants.TSG_PLATFORM_CODE + ",未找到RequestSetting";
			}

		} catch (DocumentException e) {
			logger.error("获取报文根节点失败", e);
			return "获取报文根节点失败";
		}
		return tsgPlatFormResp;
	}

//	@ApiOperation("第三方TSG请求agent入口")
//	@ApiImplicitParam(name = "xml", value = "接收的请求报文")
//	@PostMapping("/thirdToAgent")
//	@ResponseBody
//	public String chargingCenterBusiness() {
//		String tsgPlatFormResp = "";
//		String request = XmlParser.getXml(req);
//		if (StringUtils.isBlank(request))
//			logger.error("请求报文为空");
//		else
//			logger.info("请求报文为：\n" + request);
//
//		try {
//			SAXReader saxReader = new SAXReader();
//			Document document = saxReader.read(new ByteArrayInputStream(request.getBytes()));
//			Element root = document.getRootElement();
//			String command = root.getName();
//			logger.info("command:" + command);
//			String province_name = "";// 省份缩写标识
//			if (StringUtils.isNotBlank(command)) {
//				logger.info("受理TSG请求入口（新六套");
//				String orderId = StringUtils.substringBetween(request, "<ORDER_ID>", "</ORDER_ID>");
//				province_name = this.getProvince_abbreviation(orderId);//截取得到省份缩写标识
//				/*CodeRelationship codeRelationship = redisManager.getCodeRelationship(province_abbreviation,
//						Constants.VAS_PLATFORM_CODE);
//				String provinceCode="";
//				if (codeRelationship != null) {
//					logger.info("根据省份缩写标识:" + province_abbreviation + ",分省VAS平台代码:" + Constants.VAS_PLATFORM_CODE
//							+ "找到codeRelationship信息为："+codeRelationship.toString());
//					provinceCode = codeRelationship.getProvinceCode();
//				} else {
//					return "根据省份缩写:" + province_abbreviation + ",分省VAS平台代码:" + Constants.VAS_PLATFORM_CODE
//							+ ",未找到codeRelationship";
//				}*/
//				RequestSetting info = redisManager.getInfo(command, Constants.VAS_PLATFORM_CODE, province_name);
//				if (info != null) {
//					logger.info("根据command:" + command + ",平台代码:" + Constants.VAS_PLATFORM_CODE
//							+ ",省份缩写标识："+province_name+",找到RequestSetting信息为："+info.toString());
//					String platformUrl = info.getPlatformUrl();
//					logger.info("agent开始向分省转发TSG请求报文，请求地址为："+platformUrl);
//					tsgPlatFormResp = sendService.sendToSinkProvince(request, platformUrl);
//				} else {
//					logger.info("根据command:" + command + ",分省VAS平台代码:" + Constants.VAS_PLATFORM_CODE
//							+ ",省份缩写标识："+province_name+",没找到RequestSetting信息");
//					return "根据command:" + command + ",分省VAS平台代码:" + Constants.VAS_PLATFORM_CODE
//							+ ",省份缩写标识："+province_name+",没找到RequestSetting信息";
//				}
//
//			}
//			/*
//			 * if (StringUtils.isNotBlank(command)) { if
//			 * ("MPOrderNotifyReq".equals(command)) { logger.info("包月业务受理结果通知接口");
//			 *
//			 * // 解析orderId获取省份缩写 转发分省 MPOrderNotifyReq
//			 * mpOrderNotifyReq=XmlParser.getMPOrderNotifyReq(request);
//			 * if(mpOrderNotifyReq!=null &&
//			 * CollectionUtils.isNotEmpty(mpOrderNotifyReq.getMpItems())) {
//			 * if(mpOrderNotifyReq.getMpItems().get(0)!=null) {
//			 * province_abbreviation=this.getProvince_abbreviation(mpOrderNotifyReq.
//			 * getMpItems().get(0).getOrderId()); } }
//			 *
//			 * String resp = sendService.sendToSinkProvince(request,province_abbreviation);
//			 * logger.info("分省响应:" + resp); } else if
//			 * ("ChargeNotificationRequest".equals(command)) { logger.info("点播计费请求通知接口");
//			 *
//			 * // 解析orderId获取省份缩写 转发分省 ChargeNotificationRequest
//			 * chargeNotificationRequest=XmlParser.getChargeNotificationRequest(request);
//			 * if(chargeNotificationRequest!=null) {
//			 * province_abbreviation=this.getProvince_abbreviation(chargeNotificationRequest
//			 * .getOrderId()); }
//			 *
//			 * String resp = sendService.sendToSinkProvince(request,province_abbreviation);
//			 * logger.info("分省响应:" + resp); }else if("MPRelSyncReq".equals(command)) {
//			 * logger.info("订购关系同步接口"); String
//			 * prov_code=StringUtils.substringBetween(request,
//			 * "<PROV_CODE>","</PROV_CODE>");//省份编码 //TODO 根据省份编码取bug
//			 * province_abbreviation=this.getProvince_abbreviation(prov_code); String resp =
//			 * sendService.sendToSinkProvince(request,province_abbreviation);
//			 * logger.info("分省响应:" + resp); }else if("ChargeRequest".equals(command)) {
//			 * logger.info("点播计费请求确认接口（新六套"); String
//			 * orderId=StringUtils.substringBetween(request, "<ORDER_ID>","</ORDER_ID>");
//			 * province_abbreviation=this.getProvince_abbreviation(orderId); String resp =
//			 * sendService.sendToSinkProvince(request,province_abbreviation);
//			 * logger.info("分省响应:" + resp); }else if("MPOrderReq".equals(command)) {
//			 * logger.info("包月业务受理确认接口（新六套"); String
//			 * orderId=StringUtils.substringBetween(request, "<ORDER_ID>","</ORDER_ID>");
//			 * province_abbreviation=this.getProvince_abbreviation(orderId); String resp =
//			 * sendService.sendToSinkProvince(request,province_abbreviation);
//			 * logger.info("分省响应:" + resp); } }
//			 */
//
//		} catch (DocumentException e) {
//			logger.error("获取报文根节点失败", e);
//		}
//		return tsgPlatFormResp;
//	}

	@ApiOperation("第三方TSG请求agent入口")
	@ApiImplicitParam(name = "xml", value = "接收的请求报文")
	@PostMapping("/thirdToAgent")
	@ResponseBody
	public String getTsg(@RequestBody String body) {
		String tsgPlatFormResp = "";
		String request = "";
		try {
			InputStream is = new ByteArrayInputStream(body.getBytes());
			InputStreamReader inputStreamReader = new InputStreamReader(is, "UTF-8");
			BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
			// URLDecoder类包含一个decode(String s,String
			// enc)静态方法，它可以将application/x-www-form-urlencoded MIME字符串转成普通字符串；
			// URLEncoder类包含一个encode(String s,String
			// enc)静态方法，它可以将普通字符串转换成application/x-www-form-urlencoded MIME字符串。
			request = URLDecoder.decode(bufferedReader.readLine(), "UTF-8");
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		logger.info("转码后的报文：" + request);

		try {
			SAXReader saxReader = new SAXReader();
			Document document = saxReader.read(new ByteArrayInputStream(request.getBytes()));
			Element root = document.getRootElement();
			String command = root.getName();
			logger.info("command:" + command);
			String province_name = "";// 省份缩写标识
			if (StringUtils.isNotBlank(command)) {
				logger.info("受理TSG请求入口（新六套");
				province_name = StringUtils.substringBetween(request, "<PROV_CODE>", "</PROV_CODE>");
				if(StringUtils.isBlank(province_name)) {
					String orderId = StringUtils.substringBetween(request, "<OrderId>", "</OrderId>");
					if(StringUtils.isBlank(orderId)) {
						orderId = StringUtils.substringBetween(request, "<ORDER_ID>", "</ORDER_ID>");
					}
					province_name = orderId.substring(3, 5);
				}
				logger.info("province_name:" + province_name);
				RequestSetting info = redisManager.getInfo(command, Constants.VAS_PLATFORM_CODE, province_name);
				if (info != null) {
					logger.info("根据command:" + command + ",平台代码:" + Constants.VAS_PLATFORM_CODE + ",省份缩写标识："
							+ province_name + ",找到RequestSetting信息为：" + info.toString());
					String platformUrl = info.getPlatformUrl();
					logger.info("agent开始向分省转发TSG请求报文，请求地址为：" + platformUrl + "报文内容为：" + request);
					tsgPlatFormResp = sendService.sendToSinkProvince(request, platformUrl);
					logger.info("分省响应报文为：" + tsgPlatFormResp);
				} else {
					logger.info("根据command:" + command + ",分省VAS平台代码:" + Constants.VAS_PLATFORM_CODE + ",省份缩写标识："
							+ province_name + ",没找到RequestSetting信息");
					return "根据command:" + command + ",分省VAS平台代码:" + Constants.VAS_PLATFORM_CODE + ",省份缩写标识："
							+ province_name + ",没找到RequestSetting信息";
				}

			}

		} catch (DocumentException e) {
			logger.error("获取报文根节点失败", e);
		}
		return tsgPlatFormResp;
	}

	public String getProvince_abbreviation(String orderId) {
		if (StringUtils.isNotBlank(orderId)) {
			return orderId.substring(3, 5);
		}
		return null;
	}

	@ApiOperation("分省VAS到网状网请求agent请求入口")
	@ApiImplicitParam(name = "xml", value = "接收的请求报文")
	@PostMapping("/meshNetWorkToBossAgent")
	@ResponseBody
	public String boosToMeshNetWork() throws IOException, ServletException {
		String request = XmlParser.getXml(req).replaceAll("\r", "");
		logger.info("接收到的报文:\n" + request);
		String[] arr = request.split("\n");
		String str2 = arr[0].substring(2);
		String[] reqXml = StringUtils.substringsBetween(request, "<?xml", "</InterBOSS>");
		String xmlhead = "";
		String xmlbody = "";
		if (2 == reqXml.length) {
			xmlhead = "<?xml" + reqXml[0] + "</InterBOSS>>";
			xmlbody = "<?xml" + reqXml[1] + "</InterBOSS>>";
		} else {
			logger.error("报文为空或者xmlhead为空或者xmlbody为空！");
			return "";
		}
		String boosSyncOrderToMeshRsp = "";
		String BIPCode = StringUtils.substringBetween(xmlhead, "<BIPCode>", "</BIPCode>");
		String provice_name="";
		String pkgSql = StringUtils.substringBetween(request, "<PkgSeq>", "</PkgSeq>");
		if(StringUtils.isNotBlank(pkgSql)) {
			provice_name = pkgSql.substring(0, 3);
		}
		logger.info("BIPCode" + BIPCode);
		RequestSetting requestSetting = redisManager.getInfo(BIPCode, Constants.MESH_PLATFORM_CODE, provice_name);
		if (requestSetting != null) {
			//String platformUrl = "http://10.221.164.125:18989/vas/boss";
			String platformUrl = requestSetting.getPlatformUrl();
			logger.info("得到网状网平台地址，转发给网状网");
			logger.info("网状网平台地址为" + platformUrl);
			boosSyncOrderToMeshRsp = sendService.sendToThird(request, platformUrl, str2);
		} else {
			logger.info("根据command:" + BIPCode + ", 网状网平台代码:" + Constants.MESH_PLATFORM_CODE + ",未找到requestSetting");
			return "根据command:" + BIPCode + ", 网状网平台代码:" + Constants.MESH_PLATFORM_CODE + ",未找到requestSetting";
		}
		logger.info("得到网状网响应，响应为" + boosSyncOrderToMeshRsp);
		return boosSyncOrderToMeshRsp;
	}

	@ApiOperation("第三方网状网请求VAS_agent入口")
	@ApiImplicitParam(name = "xml", value = "接收的请求报文")
	@PostMapping("/boosToMeshNetWorkAgent")
	@ResponseBody
	public String meshNetWorkToBoss() {
		String request = XmlParser.getXml(req).replaceAll("\r", "");
		logger.info("接收到的报文:\n" + request);
		String[] arr = request.split("\n");
		String str2 = arr[0].substring(2);
		String[] reqXml = StringUtils.substringsBetween(request, "<?xml", "</InterBOSS>");
		String xmlhead = "";
		String xmlbody = "";
		if (2 == reqXml.length) {
			xmlhead = "<?xml" + reqXml[0] + "</InterBOSS>";
			xmlbody = "<?xml" + reqXml[1] + "</InterBOSS>";
		} else {
			logger.error("报文为空或者xmlhead为空或者xmlbody为空！");
			return "";
		}
		String pkgSeq = "";
		String BIPCode = StringUtils.substringBetween(xmlhead, "<BIPCode>", "</BIPCode>");
		if ("BIP2B413".equals(BIPCode)) {
			pkgSeq = StringUtils.substringBetween(xmlbody, "<OprNumb>", "</OprNumb>");
		} else {
			pkgSeq = StringUtils.substringBetween(xmlbody, "<PkgSeq>", "</PkgSeq>");
		}
		String provinceCode = this.getProvinceCode(pkgSeq);
		logger.info("BIPCode" + BIPCode);
		logger.info("provinceCode" + provinceCode);
		String boosSyncOrderToMeshRsp = "";
		RequestSetting requestSetting = redisManager.getInfo(BIPCode, Constants.VAS_PLATFORM_CODE, provinceCode);
		if (requestSetting != null) {
			String platformUrl = requestSetting.getPlatformUrl();
			//String platformUrl = "http://localhost:8087/miguvas/BBossOperECServlet";
			logger.info("得到分省地址，下发给分省");
			logger.info("分省地址为" + platformUrl);
			/**
			 * 请求分省，在发往分省的时候，福建是流接收，不能识别multipart/form-data;故改成text/plain;的content-type方式
			 */
			boosSyncOrderToMeshRsp = sendService.sendToThird2(request, platformUrl, str2);
		} else {
			logger.info("根据bipCode:" + BIPCode + ",分省VAS平台代码:" + Constants.VAS_PLATFORM_CODE + ",省份code：" + provinceCode
					+ ",未找到匹配地址");
			return "根据bipCode:" + BIPCode + ",分省VAS平台代码:" + Constants.VAS_PLATFORM_CODE + ",省份code：" + provinceCode
					+ ",未找到匹配地址";
		}
		logger.info("得到分省响应，响应为" + boosSyncOrderToMeshRsp);
		return boosSyncOrderToMeshRsp;

	}

	@ApiOperation("分省按次话单上传FTP")
	@ApiImplicitParam(name = "xml", value = "接收的请求报文")
	@PostMapping("/syncUserOrderToBossByFtp")
	@ResponseBody
	public String syncUserOrderToBossByFtp(@RequestBody String xml) throws ParseException {
		logger.info("接收到的分省按次话单报文:\n" + xml);
		// coreAgentHttpClient.xmlToBean(xml, load);
		String result = "0";
		String resultDesc = "操作成功";
		Document doc = null;
		try {
			doc = DocumentHelper.parseText(xml);
			Element root = doc.getRootElement();
			String headDesc = root.element("body").element("stmView").attributeValue("headDesc");
			// logger.info(headDesc);
			String middleDesc = root.element("body").element("stmView").attributeValue("middleDesc");
			String tailDesc = root.element("body").element("stmView").attributeValue("tailDesc");
			String fileNum = StringUtils.substring(headDesc, 40, 44).replace("_", "").trim();// 文件序号，左对齐右填空
			String provinceCode = StringUtils.substring(headDesc, 7, 10);
			logger.info(provinceCode);
			// logger.info(provinceCode);
			// logger.info(fileNum);
			Date fileDate = new SimpleDateFormat("yyyyMMddHHmmss").parse(StringUtils.substring(headDesc, 64, 78));// 话单文件生成时间
			// logger.info(StringUtils.substring(headDesc, 64,78));
			// logger.info(headDesc.replace("_", "") + "\r\n" + middleDesc.replace("_", "")
			// + "\r\n" + tailDesc.replace("_", "") + "\r\n");
			StmView stmView = new StmView(headDesc, middleDesc, tailDesc, fileNum, fileDate, provinceCode);
			stmViewMapper.insert(stmView);
			// Integer stmCount = Integer.valueOf(StringUtils.substring(tailDesc, 58,
			// 67));//话单总数 右对齐，左补0
			// logger.info(StringUtils.substring(tailDesc, 58, 67) + "|" + stmCount);
		} catch (DocumentException e) {
			result = "1";
			resultDesc = "解析XML结点异常";
			logger.error("解析XML结点异常", e);
		} catch (NumberFormatException e) {
			result = "1";
			resultDesc = "解析话单总数异常";
			logger.error("解析话单总数异常", e);
		}
		return returnXml(result, resultDesc);

	}


	public String returnXml(String result, String resultDesc) {
		StringBuffer buffer = new StringBuffer("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n");
		buffer.append("<message module=\"SCSP\" version=\"1.1\">\r\n");
		buffer.append("<header action=\"RESPONSE\" command=\"STMVIEW\" />\r\n");
		buffer.append("\t<body>\r\n");
		buffer.append("\t\t<stmView result=\"" + result + "\" resultDesc=\"" + resultDesc + "\"  />\r\n");
		buffer.append("\t</body>\r\n");
		buffer.append("</message>\r\n");
		logger.info("返回的报文为: " + buffer.toString());
		return buffer.toString();
	}

	@PostMapping("/test")
	public void test() throws ParseException {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
		SimpleDateFormat ymd = new SimpleDateFormat("yyyyMMdd");
		Date endTime = sdf.parse("20201102145129");
		logger.info("按次话单文件生成本地文件定时任务开启:" + sdf.format(endTime));
		Calendar startTime = Calendar.getInstance();
		startTime.add(Calendar.MINUTE, 0 - 15);
		Date starttime = sdf.parse("20201102144729");
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		List<StmView> list = stmViewMapper.selectBetweenTime(format.format(starttime),format.format(endTime));
		logger.info("" + list.size());
	}

	private String getProvinceCode(String pkgSeq) {
		String provinceCode = "";
		if (StringUtils.isNotBlank(pkgSeq)) {
			return pkgSeq.substring(0, 3);
		}
		return provinceCode;
	}

	public static void main(String[] args) {
		String a = "1230b002";
		String b = StringUtils.substring(a, 3, 7);
		System.out.println(new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()));
	}
}
